Demo

Miaolei Bao

How to install

This package is called spherical.kde. To install, run the following code (in R):

library(devtools)
devtools::install_github("Bao-Miaolei/KDE_spherical")

Upon completion, you can run the following code (in R):

library(spherical.kde)

Import data

This is a demo vignette for our package. We will use earthquake data with 77 observations contained in the ’spherepc’ package for demonstration. The data record significant earthquakes (8+ Mb magnitude) around the Pacific Ocean since 1900, collected by the U.S. Geological Survey. The data have longitude and latitude coordinates.

library(spherepc)

# Import earthquake data and select longitude and latitude coordinates
data(Earthquake)
earthquake <- cbind(Earthquake$long, Earthquake$lat)
head(earthquake)
#>          [,1]    [,2]
#> [1,] -177.657 -28.427
#> [2,] -176.461 -31.080
#> [3,] -175.626  51.499
#> [4,] -174.776  51.520
#> [5,] -174.123 -20.187
#> [6,] -173.562 -14.739

Data transformation

We want to transform spherical coordinates (longitude, latitude) to 3-dim Euclidean coordinates for analysis.

earthquake_Euc <- spherical.kde::transform_coordinates(earthquake)
head(earthquake_Euc)
#>               x           y          z
#> [1,] -0.8786891 -0.03595233 -0.4760387
#> [2,] -0.8548141 -0.05286672 -0.5162344
#> [3,] -0.6207152 -0.04747810  0.7825973
#> [4,] -0.6196568 -0.05665491  0.7828254
#> [5,] -0.9336382 -0.09610335 -0.3450853
#> [6,] -0.9609961 -0.10843841 -0.2544163

Cross validation

Then we could use cross validation to select the optimal smoothing parameter \(\kappa\).

kappa_list <- 10^seq(1, 3, length.out = 100)
optimal_kappa <- spherical.kde::cv(kappa_list, earthquake_Euc)
optimal_kappa
#> [1] 271.8588

Visualization

spherical.kde::generate_plot(earthquake_Euc, kappa = optimal_kappa)